package com.shenxuchen.crm.web.controller;

import com.shenxuchen.crm.constant.Constants;
import com.shenxuchen.crm.pojo.Dept;
import com.shenxuchen.crm.service.DeptService;
import com.shenxuchen.crm.utils.UUIDUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("dept")
public class DeptController {

    @Resource
    private DeptService deptService;

    @GetMapping("getAllDept")
    public List<Dept> getAllDept() {
        return deptService.getAllDept();
    }

    @GetMapping("checkNo")
    public Boolean checkNo(String no) {
        return deptService.checkNo(no);
    }

    @PostMapping("save")
    public Map save(Dept dept) {
        dept.setId(UUIDUtils.getUUID());
        deptService.save(dept);
        return Constants.RESP.SUC_MSG;
    }

    @GetMapping("getById")
    public Dept getById(String id) {
        return deptService.getById(id);
    }

    @PostMapping("edit")
    public Map edit(Dept dept) {
        deptService.edit(dept);
        return Constants.RESP.SUC_MSG;
    }

    @DeleteMapping("delete")
    public Map delete(String[] ids) {
        deptService.delete(ids);
        return Constants.RESP.SUC_MSG;
    }

    @GetMapping("getHasUser")
    public List getHasUser(String[] ids) {
        return deptService.getHasUser(ids);
    }
}
